package com.ky.serialport.sensor;

import com.ky.serialport.bean.ComBean;
import com.ky.serialport.utils.MyFunc;

/**
 * ±75mv无线电流传感器
 */
public class DianYa75DataBean {

    public Long time = 0L;
    public int power = 0; //电量
    public int signal = 0; //信号
    public ComBean comBean;
    public int type = -1;
    public int index = -1;
    public Float[] dianYaArray = new Float[5]; //电压数据
    public float dianYaVel = 0; //平均电压
    public Float[] dianYaOrlArray = new Float[5]; //Original 未处理电压数据
    public float dianYaOrlVel = 0; //Original 未处理平均电压


    public DianYa75DataBean() {
    }

    public DianYa75DataBean(ComBean comBean) {
        caculate(comBean.recData);
        time = comBean.recTime;
        this.comBean = comBean;
    }

    public DianYa75DataBean(byte[] recData) {
        caculate(recData);
    }

    public DianYa75DataBean caculate(ComBean comBean) {
        time = comBean.recTime;
        this.comBean = comBean;
        return caculate(comBean.recData);
    }

    public DianYa75DataBean caculate(byte[] buffer) {
        time = System.currentTimeMillis();
        signal = MyFunc.getSignal(buffer[31]); //测试信号
        power = MyFunc.getPower(buffer[29], buffer[30]);
        index = buffer[10];
        type = buffer[9];
        dianYaArray[0] = MyFunc.threeBytesToInt(buffer, 14) / 4096000f * 75f * 2 - 75f;
        dianYaArray[1] = MyFunc.threeBytesToInt(buffer, 17) / 4096000f * 75f * 2 - 75f;
        dianYaArray[2] = MyFunc.threeBytesToInt(buffer, 20) / 4096000f * 75f * 2 - 75f;
        dianYaArray[3] = MyFunc.threeBytesToInt(buffer, 23) / 4096000f * 75f * 2 - 75f;
        dianYaArray[4] = MyFunc.threeBytesToInt(buffer, 26) / 4096000f * 75f * 2 - 75f;

//        dianYaArray[0] = (float) MyFunc.threeBytes2Int(buffer, 14)/4096000f*75f*2f-75f;
//        dianYaArray[1] = (float) MyFunc.threeBytes2Int(buffer, 17)/4096000f*75f*2f-75f;
//        dianYaArray[2] = (float) MyFunc.threeBytes2Int(buffer, 20)/4096000f*75f*2f-75f;
//        dianYaArray[3] = (float) MyFunc.threeBytes2Int(buffer, 23)/4096000f*75f*2f-75f;
//        dianYaArray[4] = (float) MyFunc.threeBytes2Int(buffer, 26)/4096000f*75f*2f-75f;
        dianYaVel = (dianYaArray[0] + dianYaArray[1] + dianYaArray[2] + dianYaArray[3] + dianYaArray[4]) / 5f;


        dianYaOrlArray[0] = (float) MyFunc.threeBytesToInt(buffer, 14);
        dianYaOrlArray[1] = (float) MyFunc.threeBytesToInt(buffer, 17);
        dianYaOrlArray[2] = (float) MyFunc.threeBytesToInt(buffer, 20);
        dianYaOrlArray[3] = (float) MyFunc.threeBytesToInt(buffer, 23);
        dianYaOrlArray[4] = (float) MyFunc.threeBytesToInt(buffer, 26);
        dianYaOrlVel = (dianYaOrlArray[0] + dianYaOrlArray[1] + dianYaOrlArray[2] + dianYaOrlArray[3] + dianYaOrlArray[4]) / 5f;


        return this;
    }
}
